﻿<?php
class GalleryModel extends Model{
	public $id;
	public $afterwork_id;
	public $path;
	public $title;
	
	public function __construct()
	{
	}
	
	public static function GetAllAfterwork($afterwork_id)
	{		
		$db = new DbContext();
		$connec = $db->getConnection();
		
		$q = "SELECT g.* FROM gallery g INNER JOIN afterwork a ON a.id = g.afterwork_id WHERE a.id = :afterwork_id";
		
		$q=$connec->prepare($q);		
		$q->execute(array( 'afterwork_id' => $afterwork_id));
		$q->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, 'GalleryModel'); 
		
		return $q->fetchAll();
	}
	
	public function GetUsername()
	{
		return LoginModel::Get($this->login_id)->username;
	}
	
	public static function DeleteObsolete()
	{		
		$db = new DbContext();
		$connec = $db->getConnection();
		
		$q = "DELETE first FROM subscription AS first INNER JOIN afterwork AS second WHERE first.afterwork_id = second.id AND second.date < NOW();";
		
		$q=$connec->query($q);
	}
}
?>